package br.com.amadeus.android.util;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.SharedPreferences;

public class PreferencesNotificationService {
	
	public static void startPreferencesNotifications(SharedPreferences prefs, Context ctx, AlarmManager alarme){
		
		boolean notifyTimeline = prefs.getBoolean("ckNotificarTimeline", true);
		boolean notifySincronize = prefs.getBoolean("ckNotificarSincronize", true);
		boolean notifyForum = prefs.getBoolean("ckNotificarRespostasForum", true);
		boolean notifyBeginCourse = prefs.getBoolean("ckNotificarIniCurso", true);
		boolean notifyEndCourse = prefs.getBoolean("ckNotificarFimCurso", true);
		
		//Agendar próximas sincronizações
		if (notifySincronize) {
			String valueSinc = prefs.getString("listSincronize", String.valueOf(ConstantsAmadeusDroid.START_SYNCRONIZE));
			int minute = Integer.parseInt(valueSinc);
			PendingIntent piSync = SchedulerSyncronize.startService(minute, ctx, alarme, ConstantsAmadeusDroid.SERVICE_SYNCRONIZE);
			PendingIntentService.getInstance().setSincronizeIntent(piSync);
		}
		
		if (notifyTimeline) {
			String valueTimeline = prefs.getString("listTimeline", String.valueOf(ConstantsAmadeusDroid.START_SYNC_TIMELINE));
			int minute = Integer.parseInt(valueTimeline);
			PendingIntent piTimeline = SchedulerSyncronize.startService(minute, ctx, alarme, ConstantsAmadeusDroid.SERVICE_TIMELINE);
			PendingIntentService.getInstance().setTimelineIntent(piTimeline);
		}
		
		if (notifyForum) {
			String valueForum = prefs.getString("listForum", String.valueOf(ConstantsAmadeusDroid.START_SYNC_FORUM_MESSAGES));
			int minute = Integer.parseInt(valueForum);
			PendingIntent piForum = SchedulerSyncronize.startService(minute, ctx, alarme, ConstantsAmadeusDroid.SERVICE_FORUM);
			PendingIntentService.getInstance().setForumIntent(piForum);
		}
		
		if (notifyBeginCourse) {
			String valueBeginDate = prefs.getString("listInicioCurso", String.valueOf(ConstantsAmadeusDroid.START_INI_COURSE));
			int minute = Integer.parseInt(valueBeginDate);
			PendingIntent piBeginDate = SchedulerSyncronize.startService(minute, ctx, alarme, ConstantsAmadeusDroid.SERVICE_BEGINDATE);
			PendingIntentService.getInstance().setBeginDateIntent(piBeginDate);
		}
		
		if (notifyEndCourse) {
			String valueEndDate = prefs.getString("listFimCurso", String.valueOf(ConstantsAmadeusDroid.START_FIM_COURSE));
			int minute = Integer.parseInt(valueEndDate);
			PendingIntent piEndDate = SchedulerSyncronize.startService(minute, ctx, alarme, ConstantsAmadeusDroid.SERVICE_ENDDATE);
			PendingIntentService.getInstance().setEndDateIntent(piEndDate);
		}
	}

}
